/**
 * 
 */
package com.vincent.service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.vincent.common.Constant_User;
import com.vincent.common.Constant_Credits;
import com.vincent.dao.CreditsDAO;
import com.vincent.dao.SubjectDAO;
import com.vincent.pojo.Credits;
import com.vincent.pojo.Subject;
import com.vincent.pojo.User;

/**
 * 作者： Vincent 创建日期： 2014年4月20日 下午1:05:01 项目名字： MyForum
 */
@Component("indexService")
public class IndexService {
	@Resource
	private SubjectDAO subjectDAO;
	@Resource
	private CreditsDAO creditsDao;

	public List<Subject> getSubjects() {

		return subjectDAO.getSubjects();
	}

	public HashMap<String, Integer> checkIn(User user) {

		HashMap<String, Integer> hMap = new HashMap<>();

		if (user == null) {
			hMap.put("key", Constant_User.NOLOGIN);
		} else {

			Credits credits = creditsDao.getCredit(user);

			if (credits != null) {
				hMap.put("key", Constant_Credits.CHECKEDIN);
			} else {
				Credits credits_checkIn = new Credits();
				credits_checkIn.setFlag(Constant_Credits.CHECKIN+"");
				credits_checkIn.setLabel("签到积分");
				credits_checkIn.setNum(10);
				credits_checkIn.setReleaseDate(new Date());
				credits_checkIn.setUser(user);
				
				creditsDao.saveCredit(credits_checkIn);
				
				hMap.put("key", Constant_Credits.CHECKINOK);
			}
		}

		return hMap;
	}

}
